<template>
  <div>
    <div class="title1">
      速度参数配置
    </div>
    <div class="card pos-2">
      <el-form :model="baseForm" label-width="auto">
          <el-form-item label="速度">
            <el-input v-model.number="baseForm.speed" />
          </el-form-item>
          <el-form-item label="加速度">
            <el-input v-model.number="baseForm.accelerate" />
          </el-form-item>
          <el-form-item label="减速度">
            <el-input v-model.number="baseForm.decelerate" />
          </el-form-item>          
          <el-form-item label="轴线">
            <el-radio-group v-model="baseForm.axis">
              <el-radio value=0>X轴</el-radio>
              <el-radio value=1>Y轴</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="方向">
            <el-radio-group v-model="baseForm.direction">
              <el-radio value=true>正向</el-radio>
              <el-radio value=false>负向</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item>
            <el-button class="pry-btn" @mousedown="onSubmit" @mouseup="handleStop">行驶</el-button>
            <!-- <el-button class="cancel-btn" @click="handleStop">停止</el-button> -->
          </el-form-item>
          <!-- <el-form-item>
            <el-button type="primary" @mousedown="manualMove(0, false)" @mouseup="stop">X轴负向</el-button>
            <el-button type="primary" @mousedown="manualMove(0, true)" @mouseup="stop">X轴正向</el-button>
            <el-button type="primary" @mousedown="manualMove(1, false)" @mouseup="stop">Y轴负向</el-button>
            <el-button type="primary" @mousedown="manualMove(1, true)" @mouseup="stop">Y轴正向</el-button>
          </el-form-item> -->
        </el-form>
    </div>
  </div>
</template>

<script setup>
import { reactive } from 'vue'
import { manualMoveApi, stopMoveApi } from '@/api/drive-api'

const baseForm = reactive({
  speed: 10,
  accelerate: 500,
  decelerate: 500,
  axis: '0',
  direction: 'false'
})

function onSubmit () {
  const payload = {
        Axis: parseInt(baseForm.axis),
        Direction:Boolean(baseForm.direction),
        Speed: baseForm.speed,
        Accelerate: baseForm.accelerate,
        Decelerate: baseForm.decelerate
      };

  manualMoveApi(payload, response => {
    console.log('持续行驶成功');    
  }, error => {
    console.error('持续行驶失败', error);
  })
}

function handleStop() {
  stopMoveApi((response) => {
    console.log('停止行驶成功');
  }, (error)=> {
    console.error('停止行驶失败', error);
  })

}
</script>

<style lang="scss" scoped>
.pos-2 {
  margin-left: 5em;
  width: 50%;
  padding: 2.5em;
}
</style>